package cn.com.service.impl;

import cn.com.dao.OrderDao;
import cn.com.dao.impl.OrderDaoImpl;
import cn.com.domain.Order;
import cn.com.domain.PageBean;
import cn.com.service.OrderService;

import java.util.List;

public class OrderServiceImpl implements OrderService {
    private OrderDao dao=new OrderDaoImpl();
    @Override
    public boolean addOrder(Order order) {
        return dao.addOrder(order);
    }

    @Override
    public void delteOrderbyid(String id) {
        dao.delteOrderbyid(id);
    }

    @Override
    public void alterOrderbyid(Order order, String id) {
        dao.alterOrderbyid(order,id);
    }

    //改变数据库里的ischeck
    @Override
    public void changIsChecked(String id, String ischeck) {
        dao.changIsChecked(id,ischeck);
    }

    @Override
    public PageBean<Order> findOrderByPage(String _currentPage, String _rows) {
        int currentPage = Integer.parseInt(_currentPage);
        int rows = Integer.parseInt(_rows);
        //创建空的PageBean对象
        PageBean<Order> pb= new PageBean<Order>();
        //设置参数
        pb.setCurrentPage(currentPage);
        pb.setRows(rows);

        //调用dao查询总记录数
        int totalCount=dao.findOrderTotalCount();
        pb.setTotalCount(totalCount);
        //调用dao查询List集合
        //计算开始的记录索引
        int start=(currentPage-1)*rows;
        List<Order> list=dao.findorderByPage(start,rows);
        pb.setList(list);
        //计算总页码 比如总共5页 就是总数除以记录数字，能除尽就是totalCount/rows 不然加1
        int totalPage=totalCount % rows  == 0 ? totalCount/rows : (totalCount/rows)+1;
        pb.setTotalPage(totalPage);
        return pb;
    }

    @Override
    public double findpriceByName(String order_room_name) {
        return dao.findpriceByorder_room_name(order_room_name);
    }

    @Override
    public Order findOrderbycustomer_name(String customer_name) {
        return dao.findOrderbycustomer_name(customer_name);
    }
}
